<template>
  <div id="changedialog">
    <commonformdialog
      :isshowDialogs="isshowDialog"
      :dialogTitle="dialogTitle"
      @closetextDialog="closetextDialog"
      @confirmbtn="confirmbtn"
    >
      <div class="innerLoding">
        <el-row>
          <el-form
            :model="formData"
            :rules="rules"
            ref="ruleForm"
            label-width="120px"
            size="small"
          >
            <el-col :span="24">
              <el-form-item label="客户端名称：" prop="app_name">
                <el-input
                  placeholder="请输入客户端名称"
                  type="text"
                  clearable
                  style="width: 100%"
                  v-model="formData.app_name"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="客户端类型：" prop="client_type">
                <el-select
                  v-model="formData.client_type"
                  placeholder="请选择客户端类型"
                  style="width: 100%"
                  clearable
                >
                  <el-option
                    :label="item.lable"
                    :value="item.id"
                    v-for="(item, index) in updataOptions"
                    :key="index"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="版本名称：" prop="version_name">
                <el-input
                  placeholder="请输入版本名称"
                  type="text"
                  clearable
                  v-model="formData.version_name"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="版本号：" prop="version_code">
                <el-input
                  placeholder="请输入版本号"
                  type="text"
                  clearable
                  v-model="formData.version_code"
                >
                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="更新内容：" prop="update_info">
                <el-input
                  type="textarea"
                  :rows="3"
                  resize="none"
                  placeholder="请输入更新内容"
                  v-model="formData.update_info"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="是否必要更新:" prop="is_must">
                <el-radio-group v-model="formData.is_must">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="0">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
    </commonformdialog>
  </div>
</template>

<script type="text/javascript">
//引入弹窗
import commonformdialog from "@/components/commondialog/commondialog";
import selecteMap from "@/components/selecteMap";
import { clientversionCreate, clientversionUpdate } from "@/api/clientVersion";
export default {
  data() {
    return {
      updataOptions: [
        { lable: "安卓", id: "android" },
        { lable: "iOS", id: "ios" },
        { lable: "企业端", id: "enterprise" },
      ],
      formData: {
        client_type: "",
        version_code: "",
        version_name: "",
        app_name: "",
        update_info: "",
        is_must: 0,
      },
      rules: {
        client_type: [
          { required: true, message: "请选择客户端类型", trigger: "blur" },
        ],
        version_code: [
          { required: true, message: "请输入版本号", trigger: "blur" },
        ],

        version_name: [
          { required: true, message: "请输入版本名称", trigger: "blur" },
        ],
        app_name: [
          { required: true, message: "请输入客户端名称", trigger: "blur" },
        ],
        update_info: [
          { required: true, message: "请输入更新内容", trigger: "blur" },
        ],
      },
    };
  },
  props: {
    //是否显示弹窗
    isshowDialog: {
      type: Boolean,
      default: false,
      required: true,
    },
    //表单的名字
    dialogTitle: {
      type: String,
      default: "",
      required: true,
    },
    //是编辑还是新增
    formType: {
      type: Number,
      default: 0,
    },
    dialogdata: {
      type: Object,
    },
  },
  components: {
    commonformdialog,
  },
  methods: {
    closetextDialog() {
      this.$emit("closedialog");
    },

    confirmbtn() {
      this.$refs["ruleForm"].validate(async (valid) => {
        if (!valid) return;
        let {
          client_type,
          version_code,
          version_name,
          app_name,
          update_info,
          is_must,
        } = { ...this.formData };
        let params = {
          client_type,
          version_code,
          version_name,
          app_name,
          update_info,
          is_must,
        };
        let data;
        if (this.formType == 0) {
          data = await clientversionCreate(params);
        } else {
          params.id=this.formData.id
          data = await clientversionUpdate(params);
        }
        if (data.code == "0000") {
          this.$message({
            type: "success",
            message: data.msg,
          });
          this.$emit("confirm");
        }
      });
    },
  },
  watch: {
    isshowDialog: function (val) {
      if (!val) {
        this.$refs["ruleForm"].resetFields();
      }
    },
    dialogdata: function (val) {
      console.log(val,'-----------')
      this.formData = val;
    },
  },
  created() {},
};
</script>

<style lang="scss" scoped>
::v-deep {
  #InputSearch {
    display: none !important;
  }
  .grid-emojis {
    grid-template-columns: repeat(10, 10%) !important;
  }
  .small {
    position: absolute;
    z-index: 9;
    left: -45px;
    top: 30px;
  }
  .el-input-group__append {
    cursor: pointer;
  }
}
</style>
